﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;


namespace LiveProjectManager.DDD.Domains
{
    public class Resource : Base.Domain
    {
        // Constants.
        public const int LABEL_MAXLENGTH = 20;

        // Primary key of a resource.
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long Id { get; set; }

        // The resource label.
        [Required]
        [StringLength(LABEL_MAXLENGTH)]
        public string Label { get; set; }

        // The user who created this resource.
        [Required]
        public virtual User User { get; set; }

        // The categorization of the current resource.
        [Required]
        public virtual Category Category { get; set; }

        [Required]
        public virtual File File { get; set; }

        // The description of the resource.
        // This should create ntext column in Sql Server and not nvarchar.
        [Column(TypeName = "ntext")]
        [MaxLength]
        public string Description { get; set; }

        // The creaton date & time of this resource.
        public DateTime CreatedOn { get; set; }


        override public Dictionary<string, object> toDict()
        {
            Dictionary<string, object> myDict = new Dictionary<string, object>();
            myDict.Add("Id", Id);
            myDict.Add("Label", Label);
            myDict.Add("File", File.toDict());
            myDict.Add("User", User.toDict());
            myDict.Add("Category", Category.toDict());
            myDict.Add("Description", Description);
            myDict.Add("CreatedOn", CreatedOn);
            return myDict;
        }
    }
}
